Credential Storage And Encryption
This document explains how the application securely stores and manages credentials for OAuth2 (Gmail), SMTP, and WhatsApp authentication. It covers the storage mechanisms, encryption practices, key management, secure retrieval, and lifecycle management from creation to destruction. It also documents platform-specific protections and outlines security considerations for backups, recovery, and secure deletion.
The credential-related logic spans the Electron main process, preload bridge, and React UI components:
Electron main process initializes and manages the WhatsApp client and IPC handlers.
Preload exposes a secure API surface to the renderer.
Handlers manage Gmail OAuth2 tokens and SMTP configurations.
UI components collect user inputs and trigger secure operations.
Diagram sources
Section sources
Gmail OAuth2 token storage: Tokens are persisted locally and refreshed transparently when needed.
SMTP configuration storage: Host/port/secure/user are saved; passwords are intentionally not stored.
WhatsApp authentication: Uses local authentication strategy and cleans cache/auth files on logout/close.
Secure IPC bridge: Renderer cannot directly access Node.js APIs; only whitelisted methods are exposed.
Key security features highlighted in the project:
Context isolation and secure IPC
OAuth2 for Gmail
Encrypted storage for sensitive data
Input validation and rate limiting
Section sources
The credential lifecycle is orchestrated through the renderer UI, the preload bridge, and the main process handlers. The UI collects inputs, the preload exposes safe IPC methods, and the main process persists or retrieves credentials securely.
Diagram sources
Gmail OAuth2 Token Storage#
Token persistence: The handler stores the OAuth2 token using a secure local store after successful consent.
Retrieval: On subsequent sends, the token is retrieved from the store and applied to the OAuth2 client.
Refresh behavior: The handler reconstructs the OAuth2 client with stored credentials for sending emails.
Diagram sources
Section sources
SMTP Credentials Storage#
Configuration persistence: When requested, the handler saves host, port, secure flag, and user to the store.
Password handling: The password is not persisted; it remains in memory during the operation and is not written to disk.
Transport verification: The handler verifies connectivity before sending.
Diagram sources
Section sources
WhatsApp Authentication Data Lifecycle#
Initialization: The main process creates a WhatsApp client with a local authentication strategy.
QR generation: QR codes are generated and sent to the renderer for scanning.
Logout and cleanup: On logout or app close, the handler deletes cached and auth directories to remove traces.
Diagram sources
Section sources
Secure IPC Bridge and Renderer Exposure#
The preload script exposes a limited API surface to the renderer, preventing direct access to Node.js modules.
Renderer invokes methods like authenticateGmail, sendEmail, sendSMTPEmail, and WhatsApp controls via invoke/on patterns.
Diagram sources
Section sources
UI Credential Collection Patterns#
GmailForm: Initiates OAuth consent and displays authentication status.
SMTPForm: Collects host, port, user, password, and optional SSL/TLS toggle; supports saving non-secret config.
WhatsAppForm: Manages connection lifecycle and displays QR code and logs.
Section sources
Electron dependencies include electron-store for secure local storage, googleapis for OAuth2, nodemailer for SMTP, and whatsapp-web.js for WhatsApp integration.
The preload and main process depend on these modules to implement secure credential handling.
Diagram sources
Section sources
Token reuse: Reusing stored tokens avoids repeated OAuth flows, reducing latency.
Transport verification: Verifying SMTP connectivity once before sending improves throughput.
Rate limiting: Delays between sends mitigate provider throttling and improve reliability.
[No sources needed since this section provides general guidance]
Common credential-related issues and resolutions:
Gmail authentication failures: Verify environment variables and OAuth consent flow completion.
Missing token errors: Ensure the token was stored after consent and that the store is accessible.
SMTP connection issues: Confirm host/port/security settings and that the transport verifies successfully.
WhatsApp QR loading problems: Retry initialization and check network connectivity.
Cleanup after logout: Ensure cache and auth directories are deleted on logout or app close.
Section sources
The application implements secure credential handling by:
Using OAuth2 for Gmail with token storage and retrieval
Persisting minimal SMTP configuration while excluding passwords
Leveraging local authentication for WhatsApp and cleaning cache/auth directories on logout
Enforcing a secure IPC bridge to prevent renderer-side exposure of sensitive operations
These practices align with the documented security features and provide a robust foundation for protecting sensitive data across platforms.